package org.example.petsystem.service.impl;

import org.example.petsystem.entity.ResultBody;
import org.example.petsystem.mapper.ShopMessageBoardMapper;
import org.example.petsystem.service.ShopMessageBoardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.UUID;

@Service
public class ShopMessageBoardServiceImpl implements ShopMessageBoardService {
    @Autowired
    private ShopMessageBoardMapper shopMessageBoardMapper;

    @Override
    public ResultBody addMessage(Map<String, Object> map) {
        if (map.get("shopPhone") == null || map.get("userPhone") == null || map.get("content") == null) {
            return new ResultBody(400, "参数不完整", false);
        }
        
        map.put("messageId", UUID.randomUUID().toString());
        int result = shopMessageBoardMapper.addMessage(map);
        
        if (result > 0) {
            return new ResultBody(200, "留言成功", true);
        } else {
            return new ResultBody(400, "留言失败", false);
        }
    }

    @Override
    public ResultBody replyMessage(Map<String, Object> map) {
        if (map.get("messageId") == null || map.get("shopPhone") == null || map.get("reply") == null) {
            return new ResultBody(400, "参数不完整", false);
        }
        
        int result = shopMessageBoardMapper.replyMessage(map);
        
        if (result > 0) {
            return new ResultBody(200, "回复成功", true);
        } else {
            return new ResultBody(400, "回复失败", false);
        }
    }

    @Override
    public ResultBody getShopMessages() {
        return new ResultBody(200, "查询成功", shopMessageBoardMapper.getShopMessages());
    }

    @Override
    public ResultBody getUserMessages(Map<String, Object> map) {
        if (map.get("userPhone") == null) {
            return new ResultBody(400, "参数不完整", false);
        }
        
        return new ResultBody(200, "查询成功", shopMessageBoardMapper.getUserMessages(map));
    }

    @Override
    public ResultBody getUnreplied() {
        return new ResultBody(200, "查询成功", shopMessageBoardMapper.getUnreplied());
    }
} 